package com.neosavvy.grid.renderer {
    import com.neosavvy.grid.model.AutoFilteringDropdownVO;

    import flash.events.Event;

    import mx.controls.CheckBox;

    public class AutoFilteringGridColumnCheckboxRenderer extends CheckBox {

        override public function set data(value:Object):void {
            if (value == null) {
                value = "---";
            }

            super.data = value;

            if (value && value is AutoFilteringDropdownVO) {
                selected = (value as AutoFilteringDropdownVO).enabled;
                enabled = (value as AutoFilteringDropdownVO).removable;
                addEventListener(Event.CHANGE, changeListener);
                invalidateProperties();
            }
        }

        public function changeListener(event:Event):void {
            if (this.enabled)
                (data as AutoFilteringDropdownVO).enabled = !(data as AutoFilteringDropdownVO).enabled;
        }

    }
}